package com.tbit.uqbike.service.business.impl;

import com.github.pagehelper.PageHelper;
import com.tbit.uqbike.object.pojo.RideOrderMoneyOpeLog;
import com.tbit.uqbike.object.pojo.statistics.ExportRideOrderMoneyOpeLog;
import com.tbit.uqbike.service.business.RideOrderMoneyOpeLogService;
import com.tbit.uqbike.webmanager.dao.core.AccountUserDao;
import com.tbit.uqbike.webmanager.dao.core.UserDao;
import com.tbit.uqbike.webmanager.dao.log.RideOrderMoneyOpeLogDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 骑行订单修改记录(RideOrderMoneyOpeLog)表服务实现类
 *
 * @author jing
 * @since 2020-11-20 16:20:47
 */
@Service("rideOrderMoneyOpeLogService")
public class RideOrderMoneyOpeLogServiceImpl implements RideOrderMoneyOpeLogService {
    @Resource
    private RideOrderMoneyOpeLogDao rideOrderMoneyOpeLogDao;
    @Resource
    private AccountUserDao accountUserDao;
    @Resource
    private UserDao userDao;

    /**
     * 通过ID查询单条数据
     *
     * @param accountId 主键
     * @return 实例对象
     */
    @Override
    public RideOrderMoneyOpeLog queryById(Integer accountId) {
        return this.rideOrderMoneyOpeLogDao.queryById(accountId);
    }

    /**
     * 查询多条数据
     *
     * @param offset 查询起始位置
     * @param limit  查询条数
     * @return 对象列表
     */
    @Override
    public List<RideOrderMoneyOpeLog> queryAllByLimit(int offset, int limit) {
        return this.rideOrderMoneyOpeLogDao.queryAllByLimit(offset, limit);
    }


    /**
     * 新增数据
     *
     * @param rideOrderMoneyOpeLog 实例对象
     * @return 实例对象
     */
    @Override
    public RideOrderMoneyOpeLog insert(RideOrderMoneyOpeLog rideOrderMoneyOpeLog) {
        this.rideOrderMoneyOpeLogDao.insert(rideOrderMoneyOpeLog);
        return rideOrderMoneyOpeLog;
    }

    /**
     * 修改数据
     *
     * @param rideOrderMoneyOpeLog 实例对象
     * @return 实例对象
     */
    @Override
    public RideOrderMoneyOpeLog update(RideOrderMoneyOpeLog rideOrderMoneyOpeLog) {
        this.rideOrderMoneyOpeLogDao.update(rideOrderMoneyOpeLog);
        return this.queryById(rideOrderMoneyOpeLog.getAccountId());
    }

    /**
     * 通过主键删除数据
     *
     * @param accountId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer accountId) {
        return this.rideOrderMoneyOpeLogDao.deleteById(accountId) > 0;
    }

    @Override
    public List<RideOrderMoneyOpeLog> queryRideOrderMoneyOpeLog(RideOrderMoneyOpeLog rideorder) {
        PageHelper.startPage(rideorder.getPage().getPageNO(), rideorder.getPage().getRowCount());
        return rideOrderMoneyOpeLogDao.selectPage(rideorder);
    }

    @Override
    public List<ExportRideOrderMoneyOpeLog> export(RideOrderMoneyOpeLog rideorder) {
        List<ExportRideOrderMoneyOpeLog> exports = rideOrderMoneyOpeLogDao.export(rideorder);
        exports.stream().forEach(export -> {
            if (null != export.getAccountUserId()) {
                export.setAccountUserId(accountUserDao.getAccountUserById(Integer.parseInt(export.getAccountUserId())).getName());
            }
            if (null != export.getUserId()) {
                export.setUserId(userDao.getByUserId(Integer.parseInt(export.getUserId())).getName());
            }
        });
        return exports;
    }
}